# -*- coding: utf-8 -*-
from mod.server import extraServerApi
from mod_log import logger

from legendaryPowerScript._lpcommon import apiUtil
from legendaryPowerScript._lpcommon.serverPlugin import ServerPlugin

mainSys = None  # type: TemplateServerSystem


class TemplateServerSystem(ServerPlugin):
    """
    该mod的客户端类
    根据服务端推送下来的数据显示通用显示界面
    """

    def __init__(self, sysName):
        global mainSys
        mainSys = self
        ServerPlugin.__init__(self, sysName)

    # 在引擎加载完毕时自动调用
    def onInit(self):
        from templateServerScript.command.viewItemsCommand import ViewItemCommand
        apiUtil.getPluginManager().registerCommand("viewitem", ViewItemCommand())
        self.RegisterEventClient("ClientShoot", self, self.ClientShoot)

    def ClientShoot(self, data):
        fighter = apiUtil.getFighterById(data["playerId"])
        comp = extraServerApi.GetEngineCompFactory().CreateProjectile(fighter.getDimension())
        param = {
            "position": fighter.getEyeLocation().toFloatTuple(),
            "direction": fighter.getDirection().toFloatTuple(),
            "power": 10.0,
            "damage": 1.0,
        }
        comp.CreateProjectileEntity(fighter.entityId, "minecraft:arrow", param)